package com.company.finance.ddd.domain.core.voucher.rule.concrete;

import com.company.finance.ddd.common.FlagEnum;
import com.company.finance.ddd.domain.core.bill.aggregate.Bill;
import com.company.finance.ddd.domain.core.voucher.enums.VoucherSubjectEnum;
import com.company.finance.ddd.domain.core.voucher.rule.AbsRule;
import com.company.finance.ddd.domain.core.voucher.rule.RuleDefinition;
import com.company.finance.ddd.domain.core.voucher.rule.RuleItem;
import com.company.finance.ddd.domain.core.bill.enums.BillSubTypeEnum;
import com.company.finance.ddd.domain.core.voucher.rule.VoucherType;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wanglei
 */
public class ShouldPayRule extends AbsRule {

    @Override
    protected RuleDefinition createRuleDefinition() {
        return RuleDefinition.builder().voucherType(VoucherType.builder().code("00").name("应付").build())
                .addBillSpecification(RuleDefinition.BillSpecification.builder()
                        .prepayment(FlagEnum.NO).relateDeal(FlagEnum.NO)
                        .billSubTypeEnum(BillSubTypeEnum.SUPPLIER_EXPENSE).build())
                .addBillSpecification(RuleDefinition.BillSpecification.builder()
                        .prepayment(FlagEnum.NO).relateDeal(FlagEnum.NO)
                        .billSubTypeEnum(BillSubTypeEnum.SUPPLIER_EXPENSE).build())
                .build();
    }

    @Override
    public List<RuleItem> createRuleDefinitionItems(Bill bill) {
        String companyName = companyRepository.get(bill.getCOMPANY_ID()).getCOMPANY_NAME();

        List<RuleItem> ruleItemList = new ArrayList<>();
        ruleItemList.add(RuleItem.builder().creditSubject(VoucherSubjectEnum.BANK)
                .debitSubject(VoucherSubjectEnum.SHOULD_RECEIPT_SETTLE)
                .creditDigest(MessageFormat.format("{0}付{1}员工个人报销", companyName, bill.getBIZ_DATE()))
                .debitDigest(MessageFormat.format("{0}收到{1}", bill.getAPPLY_EMPL_ID(), companyName))
                .build());

        return ruleItemList;
    }
}
